package com.rd.sys.common.web.session;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class SingleSessionManager implements SessionManager {

    @Override
    public HttpSession createSession(HttpServletRequest request, String key, Object value) throws Exception {
        HttpSession HttpSession = request.getSession(true);
        if (null != key && null != value) {
            HttpSession.setAttribute(key, value);
            // 将session的默认时间调整为1天，每次都按照重启操作
            HttpSession.setMaxInactiveInterval(24 * 60 * 60);
        }
        return HttpSession;
    }

    @Override
    public HttpSession getSession(HttpServletRequest request) throws Exception {
        return request.getSession(false);
    }

    @Override
    public void destorySession(HttpServletRequest request) throws Exception {
        HttpSession HttpSession = request.getSession(false);
        if (null != HttpSession) {
            HttpSession.invalidate();
        }
    }

}
